package cn.zyk.condition;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.config.YamlMapFactoryBean;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.HashMap;
import java.util.Map;

// 判断当前系统是否为Windows
public class OracleDataSourceCondition implements Condition {
    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
        YamlMapFactoryBean yamlMapFactoryBean = new YamlMapFactoryBean();
        yamlMapFactoryBean.setResources(new ClassPathResource("resourcepath.yml"));
        //2.全日志源配置：dev、test、prod
        Map<String, Object> sources = yamlMapFactoryBean.getObject();

        //3.读取当前环境的资源路径配置
        Map<String, Object> conf = (HashMap<String, Object>) sources.get("spring");
        HashMap<String, String> datasource = (HashMap<String, String>) conf.get("datasource");
        String driver = datasource.get("driver-class-name");
        return StringUtils.contains(driver, "Oracle");
    }
}
